package com.wjggy.core.common.json;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

/**
 * 
 *  <p>Description: Ajax JSON处理类 </p>
 *  <p>Copyright:Copyright (c) 2012  </p>
 *  <p>Company:wjggy  </p>
 *  @author xiaofan.yu  
 *  @date   2012-1-8 下午10:09:30    
 *  @project  wjggy
 *  @version  1.0.0
 *  @see   
 *  @since 1.6
 */
public class AjaxJsonUtils   {
	/**
	 * 
	 *  @describe 返回Json
	 *  @param obj
	 *  @param request
	 *  @param response
	 *  @throws IOException
	 */
	public static  void toJson(Object obj,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		 	response.setContentType("application/json;charset=utf-8");  
		    response.setHeader("Cache-Control",  
		            "no-store, max-age=0, no-cache, must-revalidate");  
		    response.addHeader("Cache-Control", "post-check=0, pre-check=0");  
		    response.setHeader("Pragma", "no-cache");  
		    response.setCharacterEncoding("utf-8");
		    Gson gson=new Gson();
//		    System.out.println( gson.toJson(obj));
		    response.getWriter().write( gson.toJson(obj));  
	}
}
